package cn.wolfcode.rocketmq._06_delay;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

public class Producer {
    public static void main(String[] args) throws Exception {
        //1.创建出来一个生产者对象
        DefaultMQProducer defaultMQProducer = new DefaultMQProducer("producer-demo");
        //发送消息的超时时间
        defaultMQProducer.setSendMsgTimeout(10000);
        //2.绑定nameser的地址
        defaultMQProducer.setNamesrvAddr("localhost:9876");
        //3.启动生产者
        defaultMQProducer.start();
        //4.创建一个消息对象,把要发送的消息放到消息对象中
        Message message = new Message("06-delay","nihaoya".getBytes());
        //设置发送时间延迟级别
        message.setDelayTimeLevel(2);
        //5.使用生产者发送消息
        SendResult send = defaultMQProducer.send(message);
        System.out.println(send.getMsgId());
        //6.关闭资源
        defaultMQProducer.shutdown();
    }

}
